home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / complex / test.c < prev   
Encoding:
C/C++ Source or Header  |  2001-11-01  |  3.2 KB  |  121 lines

  1. /* complex/test.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <gsl/gsl_ieee_utils.h>
  24. #include <gsl/gsl_test.h>
  25. #include <gsl/gsl_math.h>
  26. #include <gsl/gsl_complex.h>
  27. #include <gsl/gsl_complex_math.h>
  28.  
  29. struct f
  30. {
  31.   char *name;
  32.   double (*f) (gsl_complex z);
  33.   double x;
  34.   double y;
  35.   double fx;
  36.   double fy;
  37. };
  38.  
  39. struct fz
  40. {
  41.   char *name;
  42.   gsl_complex (*f) (gsl_complex z);
  43.   double x;
  44.   double y;
  45.   double fx;
  46.   double fy;
  47. };
  48.  
  49. #define FN(x) "gsl_complex_" #x, gsl_complex_ ## x
  50. #define ARG(x,y) x, y
  51. #define RES(x,y) x, y
  52.  
  53. struct f list[] =
  54. {
  55. #include "results1.h"
  56.   {"", 0, 0, 0, 0, 0}
  57. };
  58.  
  59.  
  60. struct fz listz[] =
  61. {
  62. #include "results.h"
  63.   {"", 0, 0, 0, 0, 0}
  64. };
  65.  
  66. int
  67. main (void)
  68. {
  69.   size_t i = 0;
  70.  
  71.   gsl_ieee_env_setup();
  72.  
  73.  
  74.   for (i = 0 ; i < 10; i++) 
  75.     {
  76.       double r = (i - 5.0) * 0.3 ;
  77.       double t = 2.0 * M_PI * i / 5 ;
  78.       double x = r * cos(t), y = r * sin(t) ;
  79.       gsl_complex z = gsl_complex_polar (r, t) ;
  80.       gsl_test_rel (GSL_REAL(z), x, 10 * GSL_DBL_EPSILON, "gsl_complex_polar real part at (r=%g,t=%g)", r, t);
  81.       
  82.       gsl_test_rel (GSL_IMAG(z), y, 10 * GSL_DBL_EPSILON, "gsl_complex_polar imag part at (r=%g,t=%g)", r, t);
  83.     }
  84.     
  85.     i = 0;
  86.  
  87.   while (list[i].f)
  88.     {
  89.       struct f t = list[i];
  90.       gsl_complex z = gsl_complex_rect (t.x, t.y);
  91.       double f = (t.f) (z);
  92.       gsl_test_rel (f, t.fx, 10 * GSL_DBL_EPSILON, "%s at (%g,%g)", t.name, t.x, t.y);
  93.       i++;
  94.     }
  95.  
  96.   i = 0;
  97.  
  98.   while (listz[i].f)
  99.     {
  100.       struct fz t = listz[i];
  101.       gsl_complex z = gsl_complex_rect (t.x, t.y);
  102.       gsl_complex fz = (t.f) (z);
  103.       double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);
  104.  
  105. #ifdef DEBUG
  106.       printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n");
  107.       printf("y = "); gsl_ieee_fprintf_double (stdout, &t.y); printf("\n");
  108.       printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
  109.       printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
  110.       printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
  111.       printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
  112. #endif
  113.  
  114.       gsl_test_rel (fx, t.fx, 10 * GSL_DBL_EPSILON, "%s real part at (%g,%g)", t.name, t.x, t.y);
  115.       gsl_test_rel (fy, t.fy, 10 * GSL_DBL_EPSILON, "%s imag part at (%g,%g)", t.name, t.x, t.y);
  116.       i++;
  117.     }
  118.  
  119.   exit (gsl_test_summary ());
  120. }
  121.